package com.example.foo.member.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.member.model.MemberIdcard;
import com.example.foo.member.query.MemberIdcardQuery;

@org.apache.ibatis.annotations.Mapper
public interface MemberIdcardDao extends com.example.core.dao.BaseDao<MemberIdcard, Long> {

	public default PageResult<MemberIdcard> findMemberIdcards(MemberIdcardQuery memberIdcardQuery, Pageable pageable) {
		QueryWrapper<MemberIdcard> queryWrapper = createQueryWithBaseIf(memberIdcardQuery);
		//
		if (memberIdcardQuery.getState() != null) {
			queryWrapper.eq("state", memberIdcardQuery.getState());
		}
		if (StringUtils.isNotEmpty(memberIdcardQuery.getIdcard())) {
			queryWrapper.like("idcard", memberIdcardQuery.getIdcard());
		}
		if (StringUtils.isNotEmpty(memberIdcardQuery.getIdname())) {
			queryWrapper.like("idname", memberIdcardQuery.getIdname());
		}
		if (StringUtils.isNotEmpty(memberIdcardQuery.getOuterMemberId())) {
			queryWrapper.eq("outer_member_id", memberIdcardQuery.getOuterMemberId());
		}
		if (memberIdcardQuery.getUserId() != null) {
			queryWrapper.eq("user_id", memberIdcardQuery.getUserId());
		}
		return findPages(queryWrapper, pageable);
	}

}
